<template>
  <div id="index" ref="appRef">
    <div class="bg">
      <dv-loading v-if="loading">Loading...</dv-loading>
      <div v-else class="host-body">
        <div class="d-flex jc-center">
          <dv-decoration-10 class="dv-dec-10" />
          <div class="d-flex jc-center">
            <dv-decoration-8 class="dv-dec-8" :color="['#568aea', '#000000']" />
            <div class="title">
              <span class="title-text fw-b color-green">数据驾驶舱可视化</span>
              <dv-decoration-6 class="dv-dec-6" :reverse="true" :color="['#50e3c2', '#67a1e5']" />
            </div>
            <dv-decoration-8 class="dv-dec-8" :reverse="true" :color="['#568aea', '#000000']" />
          </div>
          <dv-decoration-10 class="dv-dec-10-s" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex aside-width">
            <div class="react-left ml-4 react-l-s">
              <span class="react-before"></span>
              <span class="text"></span>
            </div>
            <div class="react-right bg-color-blue ml-3">
              <span class="text fw-b">案卷总数：{{archCount}}</span>
            </div>
          </div>
          <div class="d-flex aside-width">
            <div class="react-right bg-color-blue mr-3">
              <span class="text fw-b">项目总数：{{engCount}}</span>
            </div>
            <div class="react-right mr-4 react-l-s">
              <span class="react-after"></span>
              <span class="text">{{ dateYear }} {{ dateWeek }} {{ dateDay }}</span>
            </div>
          </div>
        </div>

        <div class="body-box">
          <!-- 第三行数据 -->
          <div class="content-box">
            <dv-border-box-11 class="card">
              <bar-chart :cdata="archData" style="font-size:28px" />
            </dv-border-box-11>
            <dv-border-box-11 class="card">
              <line-chart :cdata="archData" />
            </dv-border-box-11>
            <dv-border-box-11 class="card">
              <pie-chart :cdata="archData" />
            </dv-border-box-11>
          </div>
          <div class="content-box">
            <dv-border-box-11 class="card">
              <bar-chart :cdata="engData" style="font-size:28px" />
            </dv-border-box-11>
            <dv-border-box-11 class="card">
              <line-chart :cdata="engData" />
            </dv-border-box-11>
            <dv-border-box-11 class="card">
              <pie-chart :cdata="engData" />
            </dv-border-box-11>
          </div>

          <!-- 第四行数据 -->
          <div class="bototm-box">
            <!-- <dv-border-box-13>
              <bottomLeft />
            </dv-border-box-13>
            <dv-border-box-12>
              <bottomRight />
            </dv-border-box-12>-->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import drawMixin from "../utils/drawMixin";
import { formatTime } from "../utils/index.js";
import PanelGroup from "./dashboard/PanelGroup";
import LineChart from "./dashboard/LineChart";
import RaddarChart from "./dashboard/RaddarChart";
import PieChart from "./dashboard/PieChart";
import BarChart from "./dashboard/BarChart";

import { listArchivesBar } from "@/api/system/archives";
import { listEnginBar } from "@/api/system/engin";

export default {
  mixins: [drawMixin],
  data() {
    return {
      archCount: 0,
      engCount: 0,
      timing: null,
      loading: true,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
      archData: {
        xData: [],
        seriesData: [],
        seriesName: "案卷数量"
      },
      engData: {
        xData: [],
        seriesData: [],
        seriesName: "项目数量"
      }
    };
  },
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  created() {
    listArchivesBar().then(response => {
      var array = response.rows;
      for (let i in array) {
        this.archCount = this.archCount + array[i].value;
        this.archData.seriesData.push({
          value: array[i].value,
          name: array[i].name
        });
        this.archData.xData.push(array[i].name);
      }
    });
    listEnginBar().then(response => {
      var array = response.rows;
      for (let i in array) {
        this.engCount = this.engCount + array[i].value;
        this.engData.seriesData.push({
          value: array[i].value,
          name: array[i].name
        });
        this.engData.xData.push(array[i].name);
      }
    });
  },
  mounted() {
    this.timeFn();
    this.cancelLoading();
  },
  beforeDestroy() {
    clearInterval(this.timing);
  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        this.dateDay = formatTime(new Date(), "HH: mm: ss");
        this.dateYear = formatTime(new Date(), "yyyy-MM-dd");
        this.dateWeek = this.weekday[new Date().getDay()];
      }, 1000);
    },
    cancelLoading() {
      setTimeout(() => {
        this.loading = false;
      }, 500);
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/style.scss"; // 引入全局css
@import "@/assets/scss/index.scss";
body {
  background-color: #0f1325;
}
</style>
